<html>

<head>

<?php

// Database Info
$db_user = "eqemu";			// Username
$db_pass = "eqpassword";	// Password
$db_host = "localhost";		// Hostname/IP Address
$db_name = "peq";			// Database Name
$db = mysql_connect($db_host,$db_user,$db_pass) or die(mysql_error());
mysql_select_db($db_name);
// include "../includes/constants.php";

// Default settings for output
$field = "profile";
$line_size = 16;
$limit = 20;		// Max lines to display per page. 0 to show all
$offset = 0;		// Usually won't change from 0, but can be used to set an offset starting point (in rows)

// Set values to defaults if not passed in $_GET
if (!isset($_GET[field]) || ($_GET[field] == "")) $_GET[field] = $field;
if (!isset($_GET[line_size]) || ($_GET[line_size] == "")) $_GET[line_size] = $line_size;
if (!isset($_GET[limit]) || ($_GET[limit] == "")) $_GET[limit] = $limit;
if (!isset($_GET[offset]) || ($_GET[offset] == "")) $_GET[offset] = $offset;

?>

<title></title>

<style type="text/css">
td 
{
	text-align: center;
	/* width: 5px; */
}
</style>

</head>

<body>

<form name="NoID" method="GET" action="">Enter ID: <input type="text" name="id" size="2" value="<?php echo $_GET['id']?>"><button type="submit">Go</button>&nbsp;<button type="reset">Reset</button><br>
<input type="radio" name="field" value="profile"<?php if ($_GET[field] == "profile") echo " checked"?>>Profile</input> <input type="radio" name="field" value="extprofile"<?php if ($_GET[field] == "extprofile") echo " checked"?>>Extended Profile</input><br>
Characters per line: <input type="text" name="line_size" size="2" value="<?php echo $_GET[line_size]?>"><br>
Lines per page: <input type="text" name="limit" size="3" value="<?php echo $_GET[limit]?>"><br>
Start: <input type="text" name="offset" size="3" value="<?php echo $_GET[offset]?>"><br>
</form>

<?php

if ($_GET['id']) {

	flush(); ob_flush();

	$query = "SELECT " . $_GET[field] . " FROM character_ WHERE id='" . $_GET['id'] . "' ";
	$result = mysql_query($query,$db);
	$db_row = mysql_fetch_array($result);
	$total_chars = strlen($db_row[$_GET[field]]);
	$total_chars_len = strlen($total_chars);

?>

<table border="1">
<form method="GET" action="">
<caption align="top" style="text-align:left">
<a href="?id=<?php echo $_GET['id']?>&line_size=<?php echo $_GET[line_size]?>&limit=<?php echo $_GET[limit]?>&offset=<?php if ($_GET[offset] - ($_GET[line_size] * $_GET[limit]) >= 0) {echo $_GET[offset] - ($_GET[line_size] * $_GET[limit]);};?>">&lt;&lt;Prev</a>
<a href="?id=<?php echo $_GET['id']?>&line_size=<?php echo $_GET[line_size]?>&limit=<?php echo $_GET[limit]?>&offset=<?php echo $_GET[offset] + ($_GET[line_size] * $_GET[limit]);?>">Next&gt;&gt;</a>
</caption>
</form>
<tr><td align="center">Row</td><td colspan="<?php echo $_GET[line_size]?>">Val</td><td colspan="<?php echo $_GET[line_size]?>">Char</td></tr>
<?php

	if ($_GET[limit] == 0) $_GET[limit] = ($total_chars / $_GET[line_size]) - 1;
	for ($row = $_GET[offset]; $row <= ((($_GET[line_size] * $_GET[limit]) + $_GET[offset]) - 1) && $row <= $total_chars; $row += $_GET[line_size]) {

?>
<tr><td align="right"><?php echo str_pad($row,$total_chars_len,0,STR_PAD_LEFT)?></td><?php
		//Output for HEX
		for ($char = $row; $char <= ($row + ($_GET[line_size] - 1)); $char++) {
?>
<td title="<?php echo str_pad($char,$total_chars_len,0,STR_PAD_LEFT)?>"><?php echo strtoupper(str_pad(dechex(ord($db_row[$_GET[field]][$char])),2,0,STR_PAD_LEFT))?></td><?php
		};
		
		// Output for Characters
		for ($char = $row; $char <= ($row + ($_GET[line_size] - 1)); $char++) {
?>
<td title="<?php echo str_pad($char,$total_chars_len,0,STR_PAD_LEFT)?>"><?php
			$char_dec_val = ord($db_row[$_GET[field]][$char]);
			echo "";
			if (($char_dec_val >= 33) && ($char_dec_val <= 126)) {echo $db_row[$_GET[field]][$char];}
			elseif ($char_dec_val == 32) {echo "&nbsp;";};
?></td><?php
		};
?>
</tr>
<?php
		flush(); ob_flush();
	};
?>
</table>

<?php
};
?>

</body>

</html>